<div style="text-align: center;margin-top: 5px;">
  <strong>Copyright ©2019-2021 扬州大学化学化工学院版权所有</strong>
</div>

{if $unReads}
{foreach $unReads as $key=>$unRead}
<div class="modal fade unReadNotice" id="unReadNotice{$key}" tabindex="-1"
     role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
          aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel{$key}">公告</h4>
      </div>
      <div class="modal-body">
        {$unRead['content']}
      </div>
      <div class="modal-footer">
        <button id="js-read{$key}o" type="button" class="btn btn-primary js-read"
                data-href="{:url('notice/read',['id'=>$unRead['id']])}">已读
        </button>
      </div>
    </div>
  </div>
</div>
{/foreach}
{/if}
<script>
  require(["layer_config", "ajaxForm"], function (layer) {
    var objs = $('.unReadNotice');
    var i = 0;
    console.log(objs.length);


    if (objs.length > 0) {
      showNotice(i);
    }

    function showNotice(i) {
      var obj = objs.eq(i);
      console.log(i);
      if (!obj) return false;
      $(obj).modal('show');
    }

    $("body").on("click", ".js-read", function () {
      var me = $(this), href = me.data("href");
      $.post(href, {}, function (result) {
        if (result && result.code == 1) {
          me.parents(".unReadNotice").modal('hide');
          i += 1;
          showNotice(i);
        } else {
          js_alert(result ? result.msg : '网络故障');
        }
      })
      return false;
    })


  });
</script>